package com.atguigu.gulimall.order.vo;

import com.sun.org.apache.xpath.internal.operations.Bool;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @ClassName OrderConfirmVo
 * @Description TODO
 * @Author Administrator
 * @Date 2022/7/5 23:51
 * @Version 1.0
 **/

public class OrderConfirmVo {

    //地址
    @Getter
    @Setter
    List<MemberAddressVo> address;

    //购物项
    @Getter
    @Setter
    List<OrderItemVo> items;

    //发票。。。

    //优惠
    @Getter
    @Setter
    private Integer integration;

//    private BigDecimal total;

    @Getter
    @Setter
    Map<Long, Boolean> stocks;


    //防重令牌
    @Getter
    @Setter
    String orderToken;

    public Integer getCount(){
        Integer i = 0;
        if (items != null) {
            for (OrderItemVo item : items) {
                i+=item.getCount();
            }
        }
        return i;
    }

    //订单总额
    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if (items != null) {
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

//    private BigDecimal payPrice;

    //应付总额
    public BigDecimal getPayPrice() {

        return getTotal();
    }
}
